package com.example.demo.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.Result;
import com.example.demo.entity.JobPosition;
import com.example.demo.entity.Resume;
import com.example.demo.service.JobPositionService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 职位信息表(JobPosition)表控制层
 *
 * @author makejava
 * @since 2023-12-17 00:07:10
 */
@RestController
@RequestMapping("jobPosition")
public class JobPositionController {
    /**
     * 服务对象
     */
    @Autowired
    private JobPositionService jobPositionService;

    /**
     * 分页查询所有岗位信息
     *
     * @return 所有数据
     */
    @GetMapping("list")
    public Result list(Integer current, Integer size) {
        IPage<JobPosition> pageResult = jobPositionService.selectByPage(new Page<>(current, size));
        return Result.success(pageResult);
    }


    /**
     * 根据岗位名称获取岗位信息
     *
     * @return 所有数据
     */
    @GetMapping("selectByName")
    public List<JobPosition> selectByName(@RequestParam String name) {
        System.out.println(name);
        return jobPositionService.selectByName(name);
    }

    /**
     * 新增数据
     *
     * @param jobPosition 实体对象
     * @return 新增结果
     */
    @PostMapping("insert")
    public String insert(@RequestBody JobPosition jobPosition) {
        try {
            jobPosition.setId(null);
            jobPositionService.save(jobPosition);
            return "200";
        }catch (Exception e){
            return "401";
        }
    }

    /**
     * 修改数据
     *
     * @param jobPosition 实体对象
     * @return 修改结果
     */
    @PostMapping("update")
    public String update(@RequestBody JobPosition jobPosition) {
        try {
            UpdateWrapper<JobPosition> wrapper=new UpdateWrapper<>();
            wrapper.eq("id",jobPosition.getId());
            jobPositionService.update(jobPosition,wrapper);
            return "200";
        }catch (Exception e){
            return "401";
        }
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public String delete(@RequestParam Integer id) {
        try {
            QueryWrapper<JobPosition> wrapper=new QueryWrapper<>();
            wrapper.eq("id",id);
            jobPositionService.remove(wrapper);
            return "200";
        }catch (Exception e){
            return "401";
        }
    }



}

